﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Tormenta.Utils.Animation
{
    public class MultiIntervalAnimation: List<KeyValuePair<Timer, Texture2D>>
    {
        public int CurrentIndex { get; private set; }

        public Timer CurrentTimer
        {
            get
            {
                if (this.Count != 0)
                    return this[this.CurrentIndex].Key;
                else
                    return null;
            }
        }

        public Texture2D CurrentSprite
        {
            get
            {
                if (this.Count != 0)
                    return this[this.CurrentIndex].Value;
                else
                    return null;
            }
        }

        public Vector2 Position { get; set; }
        
        public void Update(double elapsedTime)
        {
            if (this.Count != 0)
            {
                this.CurrentTimer.Update(elapsedTime);

                if (this.CurrentTimer.Overflow)
                {
                    this.CurrentIndex++;
                    if (this.CurrentIndex >= this.Count)
                        this.CurrentIndex = 0;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(this.CurrentSprite, this.Position, Util.TRANSPARENT_COLOR);
        }
        
    }
}
